<?php
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 */

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
require_once ROOT_PATH . '/lib/confs/sysConf.php';
require_once ROOT_PATH . '/lib/models/eimadmin/CompStruct.php';
include ROOT_PATH."/customConfig/attendance.config.php"; 

	$sysConst = new sysConf();
	$locRights = $_SESSION['localRights'];

	//$headingInfo =$this->popArr['headinginfo'];


?>
<head>
<link href="../../themes/<?php echo $styleSheet; ?>/css/style.css" rel="stylesheet" type="text/css"/>
<!--[if lte IE 6]>
<link href="../../themes/<?php echo $styleSheet; ?>/css/IE6_style.css" rel="stylesheet" type="text/css"/>
<![endif]-->
<!--[if IE]>
<link href="../../themes/<?php echo $styleSheet; ?>/css/IE_style.css" rel="stylesheet" type="text/css"/>
<![endif]-->
<script type="text/javascript" src="../../themes/<?php echo $styleSheet;?>/scripts/style.js"></script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="../../scripts/octopus.js"></script>
<script type="text/javascript" src="../../scripts/common.js"></script>
<script type="text/javascript" src="../../scripts/jquery/jquery.js"></script>
<script type="text/javascript">
//<![CDATA[
	function nextPage() {
		i=document.standardView.pageNO.value;
		i++;
		document.standardView.pageNO.value=i;
		document.standardView.submit();
	}

	function prevPage() {
		var i=document.standardView.pageNO.value;
		i--;
		document.standardView.pageNO.value=i;
		document.standardView.submit();
	}

	function chgPage(pNO) {
		document.standardView.pageNO.value=pNO;
		document.standardView.submit();
	}

	function sortAndSearch(sortField, sortOrder) {
		var uri = "<?php echo $_SERVER['PHP_SELF']?>?reqcode=<?php echo $this->getArr['reqcode']?>&VIEW=MAIN&sortField=" + sortField + "&sortOrder" + sortField + "=" + sortOrder;
		document.standardView.action = uri;
		document.standardView.submit();
	}


	function returnAdd() {
		location.href = "./CentralController.php?reqcode=<?php echo $this->getArr['reqcode']?>&capturemode=addmode";

	}

	function returnDelete() {
		$check = 0;
		with (document.standardView) {
			for (var i=0; i < elements.length; i++) {
				if ((elements[i].type == 'checkbox') && (elements[i].checked == true)){
					$check = 1;
				}
			}
		}

		if ( $check == 1 ){
			document.standardView.delState.value = 'DeleteMode';
			document.standardView.pageNO.value=1;
			document.standardView.submit();
		}else{
			alert("<?php echo $lang_Error_SelectAtLeastOneRecordToDelete; ?>");
		}
	}


	function returnSearch() {
		if (document.standardView.loc_code.value == -1) {
			alert("<?php echo $lang_Common_SelectField; ?>");
			document.standardView.loc_code.Focus();
			return;
		};
		document.standardView.captureState.value = 'SearchMode';
		document.standardView.pageNO.value=1;
		document.standardView.submit();
	}

	function doHandleAll()
	{
		with (document.standardView) {
			if(elements['allCheck'].checked == false){
				doUnCheckAll();
			}
			else if(elements['allCheck'].checked == true){
				doCheckAll();
			}
		}
	}

	function doCheckAll() {
		with (document.standardView) {
			for (var i=0; i < elements.length; i++) {
				if (elements[i].type == 'checkbox') {
					elements[i].checked = true;
				}
			}
		}
	}

	function doUnCheckAll()
	{
		with (document.standardView) {
			for (var i=0; i < elements.length; i++) {
				if (elements[i].type == 'checkbox') {
					elements[i].checked = false;
				}
			}
		}
	}
	
	/**
	 * If at least one day is unchecked, main check box would be unchecked
	 */

	function unCheckMain() {
		noOfCheckboxes = 0;
		noOfCheckedCheckboxes = 0;

		with (document.getElementById('standardView')) {
			for (i = 0; i < elements.length; i++) {
				if (elements[i].type == 'checkbox' && elements[i].name != 'allCheck') {
					noOfCheckboxes++;
					if (elements[i].checked == true) {
						noOfCheckedCheckboxes++;
					}

				}
			}
		}

		document.getElementById('allCheck').checked = (noOfCheckboxes == noOfCheckedCheckboxes);
	}

	function clear_form() {
		document.standardView.loc_code.options[0].selected=true;
		document.standardView.loc_name.value='';
	}

	parent.scrollTo(0, 0);
//]]>
</script>
</head>
<body>

<?php if(isset($this->getArr['capturemode']) && $this->getArr['capturemode'] == 'addmode') { ?>
<script>
function addRecord() {

	/*var cnt = document.GoodsRecord.EmpId;
	if(!(cnt.value == '') && !alpha(cnt) && !confirm('员工id不能为空')) {
		cnt.focus();
		return;
	}  if (cnt.value == '') {
		alert('<?php echo $lang_Error_LastNameEmpty?>');
		cnt.focus();
		return;
	}

	var cnt = document.GoodsRecord.Content;
	if(!(cnt.value == '') && !alpha(cnt) && !confirm('领取内容不能为空')) {
		cnt.focus();
		return;
	} else if (cnt.value == '') {
		alert('<?php echo $lang_Error_FirstNameEmpty?>');
		cnt.focus();
		return;
	}*/



	//document.GoodsRecord.sqlState.value = "NewRecord";
	document.standardView.submit();
}
</script>
<div class="formpage2col">
<form name="standardView" id="standardView" method="post" action="<?php echo $_SERVER['PHP_SELF']?>?reqcode=<?php echo $this->getArr['reqcode']?>&capturemode=updatemode">
	<div class="outerbox">
		<div class="mainHeading"><h2>奖罚</h2></div>
		<input type="hidden" name="sqlState" />
		<input type="hidden" name="Id" value="<?php echo isset($this->popArr['Id'])? $this->popArr['Id'] : '0'?>" />
		<input type="hidden" name="EmpId" id="EmpId" value="<?php echo isset($this->popArr['EmpId']) ? $this->popArr['EmpId']:'';?>" />
		<label for="txtEmpLastName">员工名字 <span class="required">*</span></label>
		<input type="text" name="EmpName" id="EmpName" class="formInputText" 
			value="<?php echo isset($this->popArr['emp_firstname']) ? $this->popArr['emp_firstname']:'';?>" onblur="GetEmpListName('<?php echo $_SERVER['PHP_SELF']?>?adcode=GetEmpName','tbname','EmpName','ShowEmpName','EmpId')"/><br>
		<div id="ShowEmpName" class="shownameclass" style="display:none"><table id="tbname" width="350" border="0" cellspacing="0" cellpadding="0"></table></div>
		<br class="clear" />
		
		<label for="txtEmpFirstName" id="txtEmpFirstName">类型<span class="required">*</span></label>
		<label class="optionlabel" for="gender1">奖励</label>
		<input type="radio" name="TypeId"  class="formRadio"  value=1 <?php echo isset($this->popArr['TypeId']) && $this->popArr['TypeId'] ==1 ? 'checked':'';?>/>
		<label class="optionlabel" for="gender1">惩罚</label>
		<input type="radio" name="TypeId"  class="formRadio"  value=2 <?php echo isset($this->popArr['TypeId']) && $this->popArr['TypeId'] ==2 ? 'checked':'';?>/>
		<br class="clear" />
		
		<label for="txtEmpFirstName" id="txtEmpFirstName"> 金额<span class="required">*</span></label>
		<input type="text" name="BonusPenaltyMoney" id="BonusPenaltyMoney" class="formInputText" 
			value="<?php echo isset($this->popArr['BonusPenaltyMoney']) ? $this->popArr['BonusPenaltyMoney']:'';?>"/>
		<br class="clear" />
		
		<label for="txtEmpFirstName" id="txtEmpFirstName">说明 <span class="required">*</span></label>
		<textarea name="Content" id="Content" class="formInputText"  rows="5" cols="20"
			 /><?php echo (isset($this->popArr['Content']))?$this->popArr['Content']:''?></textarea>
		<br class="clear" />

		<label for="txtEmpFirstName" id="txtEmpFirstName"> 生效日期<span class="required">*</span></label>
			<select name="wordYear" id="wordYear">
				<?php
					 for ($i=@date("Y");$i>=2000;$i--) {
						if (isset($this->popArr['wordYear']) && $this->popArr['wordYear']==$i) {
						   echo "<option selected value='" . $i ."'>".$i ."年</option>";
						} else {
						   echo "<option value='" . $i ."'>".$i ."年</option>";
						}
					}
				?>
			</select>
			<select name="wordMonth" id="wordMonth">
				<?php
					 for ($i=1;$i<=12;$i++) {
						if (isset($this->popArr['wordMonth']) && $this->popArr['wordMonth']==$i) {
						   echo "<option selected value='" . $i ."'>".$i ."月</option>";
						} else {
						   echo "<option value='" . $i ."'>".$i ."月</option>";
						}
					}
				?>
			</select>
		<br class="clear" />

        <div class="formbuttons">
			<input type="button" class="savebutton" id="btnEdit" onclick="addRecord(); return false;"
				onmouseover="moverButton(this);" onmouseout="moutButton(this);"
				value="<?php echo $lang_Common_Save;?>" title="<?php echo $lang_Common_Save;?>" />
			<input type="button" class="resetbutton" onclick="document.standardView.reset(); return false;"
				onmouseover="moverButton(this);" onmouseout="moutButton(this);"
				 value="<?php echo $lang_Common_Reset;?>" />
        </div>
	</div>
	<div class="requirednotice"><?php echo preg_replace('/#star/', '<span class="required">*</span>', $lang_Commn_RequiredFieldMark); ?>.</div>
	</form>
</div>
<?php } else { 
    $currentPage = $this->popArr['currentPage'];
	$emplist = $this->popArr['emplist'];
	//print_r($emplist);die(1);
	if (!isset($this->getArr['sortField']) || ($this->getArr['sortField'] == '')) {
		$this->getArr['sortField']=4;
		$this->getArr['sortOrder4']='ASC';
	}
	$TypeName = array(1=>"奖励",2=>"惩罚");
	function getNextSortOrder($curSortOrder) {
		switch ($curSortOrder) {
			case 'null' :
				return 'ASC';
				break;
			case 'ASC' :
				return 'DESC';
				break;
			case 'DESC'	:
				return 'ASC';
				break;
		}

	}

	$GLOBALS['lang_Common_SortAscending'] = $lang_Common_SortAscending;
	$GLOBALS['lang_Common_SortDescending'] = $lang_Common_SortDescending;

	function nextSortOrderInWords($sortOrder) {
		return $sortOrder == 'ASC' ? $GLOBALS['lang_Common_SortDescending'] : $GLOBALS['lang_Common_SortAscending'];
	}	
	
	
?>
<div class="outerbox">
	<form name="standardView" id="standardView" method="post" action="<?php echo $_SERVER['PHP_SELF']?>?reqcode=<?php echo $this->getArr['reqcode']?>&amp;VIEW=MAIN&amp;sortField=<?php echo $this->getArr['sortField']; ?>&amp;sortOrder<?php echo $this->getArr['sortField']; ?>=<?php echo $this->getArr['sortOrder'.$this->getArr['sortField']]?>">

		<div class="mainHeading"><h2>奖罚记录</h2></div>
		<input type="hidden" name="captureState" value="<?php echo isset($this->postArr['captureState'])?$this->postArr['captureState']:''?>" />
		<input type="hidden" name="delState" value="" />
		<input type="hidden" name="pageNO" value="<?php echo isset($this->postArr['pageNO'])?$this->postArr['pageNO']:'1'?>" />
		<input type="hidden" name="empID" value="" />


		<?php
		if (isset($this->getArr['message'])) {
			$expString  = $this->getArr['message'];
			$messageType = CommonFunctions::getCssClassForMessage($expString);
			$messageType = 'failure';
		?>
		<div class="messagebar">
			<span class="<?php echo $messageType; ?>"><?php echo $expString; ?></span>
		</div>
		<?php
		}
		?>
		<?php include("../../templates/attendance/Search2.php");?>
		

			<div class="actionbar">
				<div class="actionbuttons">
					<input type="button" class="plainbtn"
					<?php echo ($locRights['add']) ? 'onclick="returnAdd();"' : 'style=visibility:hidden;'; ?>
						onmouseover="this.className='plainbtn plainbtnhov'" onmouseout="this.className='plainbtn'"
						value="<?php echo $lang_Common_Add;?>" />


						<input type="button" class="plainbtn"
						<?php echo ($locRights['delete']) ? 'onclick="returnDelete();"' : 'style=visibility:hidden;'; ?>
							onmouseover="this.className='plainbtn plainbtnhov'" onmouseout="this.className='plainbtn'"
							value="<?php echo $lang_Common_Delete;?>" />


				</div>
				<div class="noresultsbar"><?php echo (empty($emplist)) ? "没有记录" : '';?></div>
				<div class="pagingbar">
				<?php
					$temp = $this->popArr['temp'];
					$commonFunc = new CommonFunctions();
					$pageStr = $commonFunc->printPageLinks($temp, $currentPage);
					$pageStr = preg_replace(array('/#first/', '/#previous/', '/#next/', '/#last/'), array($lang_empview_first, $lang_empview_previous, $lang_empview_next, $lang_empview_last), $pageStr);

					echo $pageStr;

					for ($j = 0; $j < 11; $j++) {
						if (!isset($this->getArr['sortOrder'.$j])) {
							$this->getArr['sortOrder'.$j] = 'null';
						}
					}
				?>
				</div>
			<br class="clear" />
			</div>
			<br class="clear" />
				<table cellspacing="0" cellpadding="0" class="data-table">
					<thead>
					<tr>
						<td width="50">
							<?php if (empty($emplist)) { ?>
							&nbsp;
							<?php } else { ?>
							<input type="checkbox" name="allCheck" id="allCheck" class="checkbox" style="margin-left:1px"
								onclick="doHandleAll()" />
							<?php } ?>
						</td>
						<?php $j = 0;
							  $sortOrder = $this->getArr['sortOrder' . $j];
						?>
						<td scope="col">员工编号</td>
						<td scope="col">员工名字</td>
						<td scope="col">所属部门</td>
						<td scope="col">类型</td>
						<td scope="col">金额</td>
						<td scope="col">原因</td>
						<td scope="col">生效日期</td>
						<td scope="col">添加时间</a></td>
						<td scope="col">录入者</a></td>
						<td scope="col">修改时间</a></td>
						<td scope="col">修改者</a></td>
						<td scope="col">审核时间</a></td>
						<td scope="col">审核者</a></td>
						<td scope="col">审核</a></td>
						<td scope="col">操作</a></td>
					</tr>
					</thead>

					<tbody>
					<?php
					//print_r($emplist);die(1);
						if ((isset($emplist)) && ($emplist !='')) {
							
							for ($j=0; $j<count($emplist);$j++) {
								$subDivision = "-";
								$compStructObj = new CompStruct();
								$compStructObj->buildAllWorkStations();
								if (isset($emplist[$j]['work_station']) && !empty($emplist[$j]['work_station'])) {
									$subDivision = $compStructObj->fetchHierarchString($emplist[$j]['work_station']);
								}
								$cssClass = ($j%2) ? 'even' : 'odd';
					?>
								<tr class="<?php echo $cssClass;?>">

									<td ><input type="checkbox" class="checkbox" name="chkLocID[]" value="<?php echo $emplist[$j]['Id']?>" onclick="unCheckMain();" /></td>
									<td ><?php echo $emplist[$j]['employee_id']; ?></td>
									<td ><?php echo (!empty($emplist[$j]['emp_firstname']))?$emplist[$j]['emp_firstname'].$emplist[$j]['emp_lastname']:""; ?></td>
									<td ><?php echo $subDivision;?></td>
									<td ><?php echo $TypeName[$emplist[$j]['TypeId']];?></td>
									<td ><?php echo (!empty($emplist[$j]['BonusPenaltyMoney']))?$emplist[$j]['BonusPenaltyMoney']:"-"; ?></td>
									<td ><?php echo (!empty($emplist[$j]['Content']))?$emplist[$j]['Content']:"-"; ?></td>
									<td ><?php echo $emplist[$j]['wordYear']."-".$emplist[$j]['wordMonth']; ?></td>
									<td ><?php echo (!empty($emplist[$j]['AddTime']))?@date("Y-m-d H:i:s",$emplist[$j]['AddTime']):"-"; ?></td>
									<td ><?php echo (!empty($emplist[$j]['Writer']))?$emplist[$j]['Writer']:"-"; ?></td>
									<td ><?php echo (!empty($emplist[$j]['MenderTime']))?@date("Y-m-d H:i:s",$emplist[$j]['MenderTime']):"-"; ?></td>
									<td ><?php echo (!empty($emplist[$j]['Mender']))?$emplist[$j]['Mender']:"-"; ?></td>
									<td ><?php echo (!empty($emplist[$j]['CheckTime']))?@date("Y-m-d H:i:s",$emplist[$j]['CheckTime']):"-"; ?></td>
									<td ><?php echo (!empty($emplist[$j]['Assessor']))?$emplist[$j]['Assessor']:"-"; ?></td>
									<td ><?php echo ($emplist[$j]['IsCheck'] ==1 )?"<font color=red>已审核</font>":"未审核"; ?></td>
									<td ><?php if($emplist[$j]['IsCheck'] != 1) {?><a target="_self" href="./CentralController.php?reqcode=<?php echo $this->getArr['reqcode']?>&capturemode=addmode&Id=<?php echo $emplist[$j]['Id']?>">编辑</a>  <a target="_self" href="./CentralController.php?reqcode=<?php echo $this->getArr['reqcode']?>&capturemode=shenhemode&Id=<?php echo $emplist[$j]['Id']?>">审核</a><?php } ?></td>
	
							</tr>
						<?php }
					  }
					?>
					</tbody>
				</table>
	</form>
</div>
<?php } ?>

<script type="text/javascript">
    <!--
    	if (document.getElementById && document.createElement) {
 			roundBorder('outerbox');
		}
    -->
</script>
</body>
</html>
